<?php
include 'inc/common.inc.php';
include 'MDecide.class.php';
include 'MCheckUser.class.php';
include 'authcode.class.php';

class Controller extends BaseController
{
	public $gatherId;

	public function informInitialize()
	{
		$code = new authcode();
		$gatherId = $this->get_request("gatherId");
		$gatherId = $code->keycode($gatherId,"DECODE");		/*需要接收传过来的request,包含聚会id*/
		$this->gatherId = $gatherId;
		$db = new MDecide();
		$item = $db->selectInformation($gatherId);
		$sortArray = array();
		foreach($item as $key=>$value)
		{
			$struct = new structTime($value['holdDate'],$value['attendNum'],$value['attendPeople'],$value['noAttendPeople'],$value['number']);
			array_push($sortArray,$struct);
		}
		$sortResult = new bestTime($sortArray);
		return $sortResult->timeArray;
	}
	
	public function refusePeople()
	{
		$gatherId = $this->gatherId;
		$db = new MDecide();
		$item = $db->refusePeople($gatherId);
		return $item;
	}
	
	public function noAnswerPeople()
	{
		$gatherId = $this->gatherId;
		$db = new MDecide();
		$item = $db->noAnswerPeople($gatherId);
		return $item;
	}
	
	public function decideDateAction()
	{
		$decideDate = $this->get_request('decideDate');
		$gatherId = $this->get_request('gatherId');
		$db = new MDecide();
		$db->updateFinalDate($gatherId,$decideDate);
	}
	
	public function clearCookieAction()
	{
		parent::clearCookie();
		$this->_msg->set(array("desc"=>"清理cookie成功","return_code"=>1));
		echo $this->_msg;
	}
	
	public function cancelAction()
	{
		$gatherId = $this->get_request('gatherId');
		$db = new MDecide();
		$db->deleteParty($gatherId);
	}
}

$control = new Controller();
$control->run();
$dbCheck = new MCheckUser();
if(!$control->get_action_name() && $dbCheck->checkSessionId())
{
	$information = $control->informInitialize();
	$refusePeople = $control->refusePeople();
	$refusePeopleCount = $refusePeople['count'];
	$refusePeopleName = $refusePeople['name'];
	$noAnswerPeople = $control->noAnswerPeople();
	$noAnswerPeopleCount = $noAnswerPeople['count'];
	$noAnswerPeopleName = $noAnswerPeople['name'];
	$gatherId = $control->gatherId;
	include template('decide.html');
}else if(!$control->get_action_name() && !$dbCheck->checkSessionId())
{
	header("Location: index.php");
}	

?>